//
//  Message.swift
//  swifttest1
//
//  Created by kologe on 2024/9/19.
//

import Foundation
import Combine

class StringMessage:BaseData{
    var hostName:String
    var message:String = "hello"
    
    override init() {
        message = "hello"
        hostName = NetMessage.shared().hostName
        super.init()
    }
    
    enum CodingKeys: String, CodingKey{
        case message
       case hostName
    }
    
    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy:CodingKeys.self)
        message = try container.decode(String.self, forKey: .message)
        hostName = try container.decode(String.self, forKey: .hostName)
       
        try super.init(from: decoder)
    }
    
    override func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(message, forKey: .message)
        try container.encode(hostName, forKey: .hostName)
        
        try super.encode(to: encoder)
    }
    
    
    
    override func textContent()->String{
        return "客户端: "+hostName+" -> "+message
    }
    
    override func getType() -> UINT32 {
        return STRING_MESSAGE;
    }
    
}
